import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'

Vue.use(Router)
//引入组件
import Login from '../views/Login'
import Home from '../views/Home'
import NotFound from '../views/common/NotFound'
import DataShow from '../views/DataShow'
import Upload from '../views/Upload'
import Collect from '../views/Collect'
import Mine from '../views/Mine'
import ProductList from '../views/Home/ProductList'
import ProductDetail from '../views/Home/ProductDetail'
import SellerDetail from '../views/Home/SellerDetail'

const router = new Router({
    routes: [
        {path: '/', redirect: '/login'},
        {path: '/login', component: Login, meta:{NoLogin: true, layout:'blank-layout'}},
        {path: '/home', component: Home},
        {path: '/datashow', component: DataShow},
        {path: '/upload', component: Upload},
        {path: '/collect', component: Collect},
        {path: '/mine', component: Mine},
        {path: '/product/list', component: ProductList},
        {path: '/product/detail', component: ProductDetail},
        {path: '/seller', component: SellerDetail},
        {path: '*', component: NotFound}
    ]
})

router.beforeEach(function(to, from, next) {
    if(to.meta.NoLogin) {
        next()
    }else {
        let token = store.getters['common/token']
        if(!!token) {
            next()
        }else{
            next('/login')
        }
    }
})

export default router
